<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use function App\Helpers\errorMsg;
use function App\Helpers\successMsg;

class UploadController extends Controller
{
    //书籍上传
    public function file(Request $request)
    {
        $file = $request->file("book");
        $extension = $file->extension();//获取文件名后缀
        if($extension != "txt") return errorMsg(-1,"文件类型格式不正确!!!");
        $path = $file->store('/uploads/book');
        $data = [
            'path' => $path,
            'site_path' => 'http://'.$_SERVER['SERVER_NAME'].'/'.$path,
        ];
        return successMsg($data);
    }

}
